<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        .wrapper {
            width: 300px;
            height: 120px;
            background-color: #ccc;
            margin: 100px auto 0;
            border: 10px solid #000;
        }

        .wrapper ul {
            padding: 0;
            margin: 0;
            list-style: none;
            width: 900px;
            height: 120px;
            margin-left: 0px;
        }

        .wrapper ul li {
            width: 300px;
            height: 120px;
            text-align: center;
            line-height: 120px;
            font-size: 30px;
            float: left;
        }

        .wrapper ul li:nth-child(1) {
            background-color: red;
        }

        .wrapper ul li:nth-child(2) {
            background-color: green;
        }

        .wrapper ul li:nth-child(3) {
            background-color: blue;
        }

        .footer {
            width: 300px;
            margin: 20px auto 0;
        }

        .footer button {
            padding: 10px 20px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="wrapper">
        <ul>
            <li>1</li>
            <li>2</li>
            <li>3</li>
        </ul>
    </div>
    <div class="footer">
        <button class="btn-prev">向左</button>
        <button class="btn-next">向右</button>
    </div>



    <script src="./tool/animateV2.0.0.js"></script>
    <script>
        // 步骤:
        // 1.0 获取相关的元素
        var ulElement = document.querySelector(".wrapper ul");
        var btnPrev = document.querySelector(".btn-prev");
        var btnNext = document.querySelector(".btn-next");

        // 2.0 定义变量
        // 索引值
        var index = 0;
        // 宽度
        var width = 300;

        // console.log(ulElement);
        // 3.0 绑定事件
        btnPrev.onclick = function () {
            index--;
            if (index < 0) {
                index = 2;
            }
            // 动画形式切换
            animate(
                ulElement,
                "marginLeft",
                -index * width
            )
            console.log(-index * width);
        }
        btnNext.onclick = function () {
            // 索引值自增
            index++;
            // 不让超出范围
            if (index > 2) {
                // 重置为0
                index = 0;
            }
            // 动画形式切换
            animate(
                ulElement,
                "marginLeft",
                -index * width
            )
            console.log(-index * width);
        }



    </script>
</body>

</html>